package com.haoniu.web.controller.module;

import com.haoniu.common.annotation.Log;
import com.haoniu.common.base.AjaxResult;
import com.haoniu.common.enums.BusinessType;
import com.haoniu.framework.util.ShiroUtils;
import com.haoniu.framework.web.page.TableDataInfo;
import com.haoniu.module.domain.database.WelfareRoom;
import com.haoniu.module.service.WelfareRoomService;
import com.haoniu.web.core.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 福利房 信息操作处理
 *
 * @author houyijun
 * @date 2019-04-22
 */
@Controller
@RequestMapping("/module/welfareRoom")
public class WelfareRoomController extends BaseController
{
    private String prefix = "module/welfareRoom";

	@Autowired
	private WelfareRoomService welfareRoomService;

	@RequiresPermissions("module:welfareRoom:view")
	@GetMapping()
	public String welfareRoom()
	{
	    return prefix + "/welfareRoom";
	}

	/**
	 * 查询福利房列表
	 */
	@RequiresPermissions("module:welfareRoom:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WelfareRoom welfareRoom) {
		startPage();
        List<WelfareRoom> list = welfareRoomService.selectWelfareRoomList(welfareRoom);
		return getDataTable(list);
	}

	/**
	 * 新增福利房
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存福利房
	 */
	@RequiresPermissions("module:welfareRoom:add")
	@Log(title = "福利房", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WelfareRoom welfareRoom) {
        welfareRoom.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(welfareRoomService.insertWelfareRoom(welfareRoom));
	}

	/**
	 * 修改福利房
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		WelfareRoom welfareRoom = welfareRoomService.selectWelfareRoomById(id);
		mmap.put("welfareRoom", welfareRoom);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存福利房
	 */
	@RequiresPermissions("module:welfareRoom:edit")
	@Log(title = "福利房", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WelfareRoom welfareRoom) {
        welfareRoom.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(welfareRoomService.updateWelfareRoom(welfareRoom));
	}

	/**
	 * 删除福利房
	 */
	@RequiresPermissions("module:welfareRoom:remove")
	@Log(title = "福利房", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(welfareRoomService.deleteWelfareRoomByIds(ids));
	}

}
